<?php

namespace app\wechat\controller;
use app\admin\controller\Backend;

/**
 * 微信配置管理
 *
 * @icon fa fa-circle-o
 */
class Config extends Backend
{
    protected $configs = [];

    public function _initialize() {
        parent::_initialize();
        $this->configs = config('wechat');
    }

    public function index() {
        if($this->request->isPost()) {
            $post = $this->request->post('row/a');
            $path = APP_PATH . 'extra' . DS . 'wechat.php';
            if(file_put_contents($path, '<?php' . "\n\nreturn " . var_export($post, true) . ";") === false) {
                return $this->error("配置文件" . $path . "保存失败");
            }
            return $this->success("Option");
        }

        return $this->view
            ->assign('configs', $this->configs)
            ->assign('nav', $this->request->get('nav', 'news'))
            ->fetch();
    }
}